﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;

namespace MachineVision.Shared.Extensions
{
    public interface IAppMapper
    {
        public IMapper Current { get; set; }
        T Mapper<T>(object source);
    }

    public class AppMapper : IAppMapper
    {
        public AppMapper()
        {
            var mapconfig = new MapperConfiguration(x =>
            {
                x.AddMaps(AppDomain.CurrentDomain.GetAssemblies());
            });
            Current = mapconfig.CreateMapper();
        }

        public IMapper Current { get; set; }

        public T Mapper<T>(object source) => Current.Map<T>(source);
    }
}
